package chapter8.section5;

//����8-6��һ��Map�ĵ���Ӧ��

import chapter6.section3.Account;
import chapter8.section4.AccountRoster;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class AccountMapRoster {
    private final Map<String, Account> roster = new HashMap<>();

    public static void main(String[] args) {
        AccountRoster roster = new AccountRoster();
        roster.add(new Account("001", "����", 1000));
        roster.add(new Account("002", "½��һ", 1000));
        roster.add(new Account("003", "�ο�", 1000));
        roster.print();
        System.out.println("--��ѯ�˺�Ϊ002���˻���Ϣ--");
        Account result = roster.find("005");
        if (result == null) {
            System.out.println("û�з���002���˻���Ϣ");
        } else {
            System.out.println(result);
        }
    }

    // ��û��������˻�������
    public int size() {
        return roster.size();
    }

    public void add(Account account) {
        roster.put(account.getId(), account);
    }

    // ��ʾ�����˻���Ϣ��Ĭ�����
    public void print() {
        Iterator<Account> it = roster.values().iterator();
        while (it.hasNext()) {
            Account account = it.next();
            System.out.println(account);
        }
    }

    // Ѱ�Ҽ������Ƿ����ָ��id���˻�
    public Account find(String id) {
        Account result = roster.get(id);
        return result;
    }
}
